package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(Long userId);

    /**
     * 添加地址
     * @param addressBook
     */
    void addAddress(AddressBook addressBook);

    /**
     * 设置默认地址
     * @param addressBook
     */

    void setDefault(AddressBook addressBook);


    /**
     * 根据默认状态查询
     * @param userId
     * @return
     */
    @Select("select * from address_book where is_default = 1 and user_id = #{userId}")
    List<AddressBook> findByIsDefault(Long userId);

    /**
     * 根据id查询地址
     * @param id
     * @return
     */

    @Select("select * from address_book where id = #{id}")
    AddressBook findById(Long id);

    /**
     * 修改地址
     * @param addressBook
     */
    @Update("update address_book set consignee = #{consignee},sex = #{sex},phone = #{phone},province_code = #{provinceCode},province_name = #{provinceName}" +
            ",city_code = #{cityCode},district_code = #{districtCode},district_name = #{districtName},detail = #{detail},label = #{label} where user_id = #{userId} and id = #{id}")
    void update(AddressBook addressBook);

    /**
     * 删除地址
     * @param addressBook
     */
    @Delete("delete from address_book where user_id = #{userId} and id = #{id}")
    void delete(AddressBook addressBook);
}
